import wxkfConfig from '../../../../api/config/channel/wxkf-config'
import * as globalTypes from '../../../../mutation-types'

/**
 * 查询微信官方客服授权地址
 * @param data
 */
export const getWxkfAuthUrl = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.getWxkfAuthUrl(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询微信官方客服列表
 * @param data
 */
export const getWxkfWorkConfigs = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.getWxkfWorkConfigs(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 增加授权管理客服账号
 * @param data
 */
export const addWxkfAccount = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.addWxkfAccount(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 修改授权管理客服账号
 * @param data
 */
export const updateWxkfAccount = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.updateWxkfAccount(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除授权管理客服账号
 * @param data
 */
export const deleteWxkfAccount = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.deleteWxkfAccount(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 获取微信官方客服接入列表
 * @param data
 */
export const getWxkfConfigs = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.getWxkfConfigs(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 添加微信官方客服接入
 * @param data
 */
export const saveWxkfConfig = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.saveWxkfConfig(data)
    .then(response => {
      if (response.success) {
        return response
      } else {
        return response
      }
    })
    .catch(() => {
      console.log(data)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新微信官方客服接入
 * @param data
 */
export const updateWxkfConfig = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.updateWxkfConfig(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除微信官方客服接入
 * @param data
 */
export const removeWxkfConfig = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.removeWxkfConfig(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除微信官方客服接入
 * @param data
 */
export const getContactWay = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.getContactWay(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 根据ID获取微信客服接入号
 * @param data
 */
export const getWxkfConfigById = ({commit, state, rootState, dispatch}, data) => {
  return wxkfConfig.getWxkfConfigById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}